package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCarService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/user/shoppingCart")
public class ShoppingCarController {
    @Autowired
    private ShoppingCarService shoppingCarService;
    @PostMapping("/add")
    @ApiOperation("购物车接口")
    public Result shoppingCar(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCarService.add(shoppingCartDTO);
        return null;
    }

    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public Result<List<ShoppingCart>> listShoppingCart(){
       List<ShoppingCart> list =  shoppingCarService.list();
       return Result.success(list);
    }

    @DeleteMapping("/clean")
    public Result cleanShoppingCart(){
        shoppingCarService.clean();
        return Result.success();
    }

}
